#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "../framework/GameActivity.h"
#include "ChineseGameFactory.h"
#include "../framework/ChessBoardImp1.h"
#include "../framework/HumanMethodMove.h"
#include <QWidget>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    cout<<"in mainwindows"<<endl;
    ui->setupUi(this);
    //new a chess game here
    game = new GameActivity(new ChineseGameFactory);
    //initialize the chess game
    game->onCreate();
    //initial chess board widget
    ui->widget->setChessBoard(game->getChessBoard());
    ui->widget_2->setSide("red");
    ui->widget_2->setVisible(false);
    ui->widget_3->setSide("black");
    ui->widget_3->setVisible(false);
    QObject::connect(game,SIGNAL(updateUI()),game,SLOT(notify()));
    QObject::connect(ui->widget,SIGNAL(mouseClicked(int,int)),game,SLOT(setPoint(int,int)));
    //add chessboard widget
    game->addWidget(ui->widget);
    game->addWidget(ui->widget_2);
    game->addWidget(ui->widget_3);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{

    //start the game
    if(ui->radioButton->isChecked()){
        game->addPlayer("red",new HumanMethodMove);
    }
    else{
        //game->addPlayer("red",new OthelloAIGreedy);
    }
    if(ui->radioButton_3->isChecked()){
        game->addPlayer("black",new HumanMethodMove);
    }
    else{
        //game->addPlayer("black",new OthelloAIGreedy);
    }
    ui->widget_2->setVisible(true);
    game->onStart();

}

void MainWindow::on_pushButton_2_clicked()
{
    game->onStop();

}

void MainWindow::on_pushButton_3_clicked()
{
    game->onReset();
}
